﻿using System;
using System.Collections.Generic;
using Scaredfinger.JSShell;
using System.Reflection;
using System.IO;

namespace SampleShell
{
  class Program
  {
    static void Main(string[] args)
    {
      ShellFactory<SampleShell>.Default.AddImport("System");
      ShellFactory<SampleShell>.Default.AddImport("System.Reflection");
      ShellFactory<SampleShell>.Default.AddImport("System.Collections");
      ShellFactory<SampleShell>.Default.AddImport("System.Windows.Forms");
      ShellFactory<SampleShell>.Default.AddImport("System.Reflection");
      ShellFactory<SampleShell>.Default.AddImport("System.Drawing");
      ShellFactory<SampleShell>.Default.AddImport("System.IO");
      ShellFactory<SampleShell>.Default.AddImport("System.Threading");

      Assembly.GetExecutingAssembly();
      Directory.GetLogicalDrives();

      using (var shell = ShellFactory<SampleShell>.Default.CreateShell())
      {
        shell.OpenShell();
        shell.AddGlobalObject("tokens", new List<string>());
        shell.AddGlobalObject("globals", new Dictionary<string, object>());
        
         try
          { 
            string filePath = Directory.GetCurrentDirectory();
            //Console.WriteLine("The current directory is {0}", filePath);
            
            StreamReader streamReader = new StreamReader(filePath + "/main.js");
            string text = streamReader.ReadToEnd();
            streamReader.Close();

            var result = shell.Eval(text); 
          }
          catch (Exception ex)
          {
            Console.WriteLine(ex);
          }
        do
        {
          Console.Write(">");
          try
          {
            var result = shell.Eval(Console.ReadLine());
          }
          catch (Exception ex)
          {
            Console.WriteLine(ex);
          }
        } while (shell.Running);
      }
    }
  }
}
